<include file="public:header" />
  <div class="toptip">
    <div class="toptit">提示：</div>
    <p>正式使用后删除分类会导致与此分类关联的信息类别丢失，修改不会受影响。</p>
    <p>删除顶级级分类将会自动删除此分类下的子分类。</p>
  </div>
<form action="{:U('Config/edit')}" method="post">
    <div class="toptit">地区层级配置</div>
    <div class="form_main width120">
        <div class="fl">默认地区：</div>
        <div class="fr">
            <input id="default_district_cn" readonly="readonly" type="text" class="J_resuletitle_city input_text_default small" data-toggle="funCityModal" data-title="请选择地区" data-multiple="false" data-maximum="0" data-width="630" value="{$default_district.district_cn_all|default='请选择默认地区'}">
            <input name="default_district" id="default_district" class="J_resultcode_city" type="hidden" value="{$district_end}">
        </div>
        <div class="fl"></div>
        <div class="fr">
            <input type="submit" name="submit" class="admin_submit" value="保存修改"/>
        </div>
        <div class="clear"></div>
    </div>
</form>
<form action="{:U('districtAllSave')}" id="form1" name="form1" method="post">
    <div class="list_th">
        <div class="td" style=" width:60%;">
            <div class="left_padding">分类名称</div>
        </div>
        <div class="td" style=" width:20%;">排序</div>
        <div class="td" style=" width:20%;">
            <div class="list_right">操作</div>
        </div>
        <div class="clear"></div>
    </div>

    <volist name="district" id="vo">
        <div class="list_tr link_bk">
            <div class="td" style=" width:60%;">
                <div class="category_img J_show" id="{$vo.id}" level="1"></div>
                <div class="category_input">
                    <input name="save_id[]" type="hidden" value="{$vo.id}"/>
                    <input name="categoryname[]" type="text" class="input_text_default small" maxlength="20"
                           value="{$vo.categoryname}" style=" width: 120px;"/>
                    <span style="color:#999999; margin-left: 5px; font-size: 13px;">(id:{$vo.id},别名:<if condition="$vo['spell']">{$vo.spell}<else />--</if>)</span>
                </div>
                <div class="clear"></div>
            </div>
            <div class="td" style=" width:20%;">
                <input name="category_order[]" type="text" class="input_text_default small" maxlength="3"
                       value="{$vo.category_order|default=0}" style="width:50px;"/>
            </div>
            <div class="td edit" style=" width:20%;">
                <div class="list_right btn">
                    <a href="{:U('add',array('pid'=>$vo['id']))}">此类下添加子类</a>
                    <a href="{:U('edit',array('id'=>$vo['id']))}">修改</a>
                    <a href="{:U('delete',array('id'=>$vo['id']))}" class="gray" onclick="return confirm('你确定要删除吗？')">删除</a>
                </div>
            </div>
            <div class="clear"></div>
        </div>
    </volist>
    <div class="list_tr">
        <div class="td" style="width: 60%;">
            <div class="J_add category_list_add" level="1" parentid="0">添加分类</div>
            <div class="clear"></div>
        </div>
    </div>
</form>

<div class="list_foot">
    <div class="btnbox">
        <input type="submit" class="admin_submit" id="ButSave" value="保存分类"/>
        <input type="button" class="admin_submit" id="ButAdd" value="添加分类" onclick="window.location='{:U('add')}'"/>
    </div>
    <div class="footso"></div>
</div>

</div>
<include file="public:footer" />
<qscms:load type="category"/>
<script type="text/javascript" src="../public/js/jquery.default.city.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    var Maxlevel=6;//最多分类层数
    //打开子菜单
    $(".J_show").live('click', function () {
        var sub_box = $(this).closest(".list_tr").next('.j_smalldiv');
        var level = $(this).attr('level');
        sub_box.is(':visible') ? $(this).removeClass("show") : $(this).addClass("show");
        if (sub_box.length == 0 && level < Maxlevel) {
            get_menu($(this).attr('id'), $(this).closest(".list_tr"), level);
        }
        else {
            sub_box.toggle();
        }

    });
    //生成分类
    function get_menu(pid, thisobj, level) {
        var tsTimeStamp = new Date().getTime();
        $.getJSON("{:U('index')}", {"pid": pid}, function (result) {
            if (result.status == 1) {
                var html = "";
                var leftbg = "";
                var i = 1;
                level++;
                if (pid) {
                    for (x in result.data) {
                        html += "<div class=\"list_tr link_bk\">";
                        html += "<div class=\"td\" style=\"width:60%\">";
                        html += "<div class=\"category_sub_img l" + level + "\">&nbsp;</div>";
                        html += "<div class=\"category_img J_show\" id=\"" + result.data[x]['id'] + "\" level=\"" + level +"\"></div>";
                        html += "<div class=\"category_input\">";
                        html += "<input name=\"save_id[]\" type=\"hidden\" value=\"" + result.data[x]['id'] + "\"/>";
                        //html += "<input name=\"pid[]\" type=\"hidden\" value=\"" + result.data[x]['pid'] + "\"/>";
                        html += "<input name=\"categoryname[]\" type=\"text\" value=\"" + result.data[x]['categoryname'] + "\" class=\"input_text_default small\" maxlength=\"20\" style=\"width: 120px;\"/>";
                        html += "<span style=\"color:#999999; margin-left: 5px; font-size: 13px;\">(id:" + result.data[x]['id'] + ",别名:" + (result.data[x]['spell'] ? result.data[x]['spell'] : '--') + ")</span>";
                        html += "</div>";
                        html += "<div class=\"clear\"></div>";
                        html += "</div>";
                        html += "<div class=\"td\" style=\"width:20%\"><input name=\"category_order[]\" type=\"text\"  value=\"" + result.data[x]['category_order'] + "\" class=\"input_text_default small\" maxlength=\"3\" style=\"width: 50px;\"/></div>";
                        html += "<div class=\"td edit\" style=\"width:20%\"><div class=\"list_right btn\">";
                        if (level < Maxlevel) {
                            html += "<a href=\"{:U('add')}&pid=" + result.data[x]['id'] + "\">此类下添加子类</a>";
                        }
                        html += "<a href=\"{:U('edit')}&id=" + result.data[x]['id'] + "\">修改</a>";
                        html += "<a onclick=\"return confirm('你确定要删除吗？')\" href=\"{:U('delete')}&id=" + result.data[x]['id'] + "\" class=\"gray\">删除</a>";
                        html += "</div></div>";
                        html += "<div class=\"clear\"></div>";
                        html += "</div>";
                        i++;
                    }
                }
                if (level <= Maxlevel) {
                    html += "<div class=\"list_tr\"><div class=\"td\" style=\"width:60%;\"><div class=\"category_sub_img last l" + level + "\">&nbsp;</div><div class=\"J_add category_list_add\" level=\"" + level + "\" parentid=\"" + pid + "\">添加分类</div><div class=\"clear\"></div></div></div>";
                }
                thisobj.after('<div class="j_smalldiv">' + html + '</div>');
            }
        });
    }
    //添加分类
    $(".J_add").live('click', function () {
        var level=$(this).attr('level');
        var pid=$(this).attr('parentid');
        var html = '';
        html += "<div class=\"list_tr link_bk\">";
        html += "<div class=\"td\" style=\"width:60%\">";
        if (level>1)
        {
            html += "<div class=\"category_sub_img l" + level + "\">&nbsp;</div>";
        }
        html += "<div class=\"category_img J_show\" id=\"\" level=\"" + level +"\"></div>";
        html += "<div class=\"category_input\">";
        html += "<input name=\"add_parentid[]\" type=\"hidden\" value=\"" + pid + "\"/>";
        html += "<input name=\"add_categoryname[]\" type=\"text\" value=\"\" class=\"input_text_default small\" maxlength=\"20\" style=\"width: 120px;\"/>";
        html += "</div>";
        html += "<div class=\"clear\"></div>";
        html += "</div>";
        html += "<div class=\"td\" style=\"width:20%\"><input name=\"category_order[]\" type=\"text\"  value=\"0\" class=\"input_text_default small\" maxlength=\"3\" style=\"width: 50px;\"/></div>";
        html += "<div class=\"clear\"></div>";
        html += "</div>";
        $(this).parent().parent().before(html);
    });
    //添加分类
    $("#ButSave").live('click', function () {
        $("form[name='form1']").submit();
    });
    /*$("#default_district_cn").click(function () {
        var qsDialog = $(this).dialog({
            title: '地区选择',
            loading: true,
            footer : false
        });
        var url = "{:U('CategoryDistrict/ajax_district')}";
        $.getJSON(url, function (result) {
            qsDialog.setContent(result.data);
        });
    });*/
    function set_district_input(a,b){
        $('#s_district').val(a);
        $('#s_level').val(b);
    }
});
</script>
</body>
</html>